package com.jash.labor.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jash.labor.context.Result;
import com.jash.labor.entity.Labor;
import com.jash.labor.mapper.LaborMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class LaborService {
    @Resource
    private LaborMapper laborMapper;

    /*
    添加
     */
    public Object add(Labor labor) {
        labor.setCreatetime(new Timestamp(System.currentTimeMillis()));
        System.out.println(labor);
        laborMapper.insert(labor);

        //增删改操作 返回
        return Result.SUCCESS;
    }

    /*
    编辑
     */
    public Object edit(Labor labor) {
        laborMapper.updateById(labor);
        //增删改操作 返回
        return Result.SUCCESS;
    }

    /*
    查询
     */
    public Object queryListPage(String sex, Integer pageNo, Integer pageSize) {
        Page<Labor> page = new Page(pageNo, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sex", sex);
        IPage iPage = laborMapper.selectPage(page, wrapper);
        return new Result<>(iPage);
    }

    //按id查询工人详情信息
    public Object selectLaborId(Integer id){

        return new Result<>(laborMapper.selectLaborId(id));
    }

    //按id查询  通过自己 分享  报名人数
    public Object selectLaborEnroll(Integer id,Integer pageNo, Integer pageSize){

        Page<HashMap> page = new Page(pageNo,pageSize);

        IPage<HashMap> iPage = laborMapper.selectLaborEnroll(page,id);

        return new Result<>(iPage);
    }
    //按id查询  通过自己 分享  成功入职的人数
    public Object selectLaborCheck(Integer id,Integer pageNo, Integer pageSize){

        Page<HashMap> page = new Page(pageNo,pageSize);

        IPage<HashMap> iPage = laborMapper.selectLaborCheck(page,id);

        return new Result<>(iPage);
    }
    //提现
    public Object selectLaborCheckIs(Integer id,Integer pageNo, Integer pageSize){

        Page<HashMap> page = new Page(pageNo,pageSize);

        IPage<HashMap> iPage = laborMapper.selectLaborCheckIs(page,id);

        return new Result<>(iPage);
    }




}
